Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively#5
Draft
Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively#5
Conversation
…in the sidebar DocFX was treating all story TOC items as the same page because they all pointed to storybook.html with different ?story= query params, which DocFX ignores for active-state matching. Fix: during pre-processing, generate a stub .md file for each story in a stories/ subdirectory. DocFX builds these into unique HTML pages so each story has its own URL. DocFX's native active-state detection then works correctly — only the current story is highlighted in the sidebar. Post-processing now injects a simplified iframe (no JS workarounds needed) for story-specific pages, and retains backward-compatible ?story= URL handling on the main storybook page. Co-authored-by: einari <134365+einari@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Storybook integration in DocFX navigation sidebar
Fix Storybook sidebar: generate per-story pages so DocFX active-state works natively
Mar 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DocFX ignores query string parameters when computing TOC active state. All story sidebar items shared
storybook.htmlas their base URL (differentiated only by?story=), causing DocFX to mark every story as active simultaneously.Approach
Replace the single-page + query-param model with individual HTML pages per story. Each story now gets a unique URL (
stories/{storyId}.html), so DocFX's native active-state, breadcrumb, and highlighting all work correctly without any JS workarounds.Changes
preprocess-storybooks.tsgenerateStoryFiles(): creates stub.mdfiles understories/for each story in the Storybook index, with front matter embedding the story's path and ID. Writes a.gitignoreto prevent accidental commits of generated filesbuildTocFromStorybook(): TOC hrefs changed fromstorybook.md?story={id}→stories/{id}.mdupdateTocWithStorybook(): also updates the root Storybook TOC entry to point to the first story pageprocessMarkdownFile(): callsgenerateStoryFiles()and skips already-generated story pages (guard against recursion)postprocess-storybooks.tsinjectStorybookIframe(storyId?): story-specific pages get a simplified iframe with the story URL hardcoded — thefixTocActiveState,fixBreadcrumb, and "first story redirect" JS hacks are removed entirely?story=URL param handling for existing linksStorybookConfiginterface: addedstory?: stringGenerated stub example
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.